<?php
	function cookieAuth(){
	#User is redirected here from login.php
	
	if(!isset($_COOKIE['username'])){
		
		$url = 'http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
		
		if((substr($url,-1) == '/') OR (substr($url,-1) == '\\')){
			$url = substr($url,0,-1);
		}
		
		$url .= 'index.php';
		header("Location: $url");
		exit();
	}
	
	echo "You are now logged in,{$_COOKIE['username']}!And you userid is {$_COOKIE['userid']}";
	
}

	header('Content-Type:text/html;charset=utf-8');
	cookieAuth();

?>